using System;
using System.Linq;
using System.Text;
using System.Transactions;
using System.Collections.Generic;
using System.Data.Linq;
using EF.Commons.Background.Entity;

namespace Common.Background.Data
{

    /// <summary>
    /// 
    /// </summary>
    public class WebManageUser_WebManageRolesRepository : BackgroundRepositoryBase, IWebManageUser_WebManageRolesRepository
    {
        IWebManageUsersRepository iWebManageUsersRepository = null;
        IWebManageRolesRepository iWebManageRolesRepository = null;
        public WebManageUser_WebManageRolesRepository()
        {
            iWebManageUsersRepository = new WebManageUsersRepository();
            iWebManageRolesRepository = new WebManageRolesRepository();
        }

        #region IWebManageUser_WebManageRolesRepository 成员



        public IQueryable<WebManageUser_WebManageRoles_Ext> GetDetailModel()
        {
            var linq = from data in this.GetEntities<WebManageUser_WebManageRoles>()
                       join data2 in iWebManageUsersRepository.GetEntities<WebManageUsers>()
                       on data.ManageUserID equals data2.ManageUserID
                       join data3 in iWebManageRolesRepository.GetEntities<WebManageRoles>()
                       on data.ManageRoleID equals data3.ManageRoleID
                       select new WebManageUser_WebManageRoles_Ext
                       {
                           ManageRoleID = data.ManageRoleID,
                           ManageUserID = data.ManageUserID,
                           WebManageRoles_Extend = data3,
                           WebManageUsers_Extend = data2,
                       };

            return linq;
        }

        public void DeleteForUserID(int userid)
        {
            var list = new List<WebManageUser_WebManageRoles>();
            this.GetEntities<WebManageUser_WebManageRoles>().Where(i => i.ManageUserID == userid).ToList().ForEach(i =>
            {
                list.Add(new WebManageUser_WebManageRoles
                {
                    ManageRoleID = i.ManageRoleID,
                    ManageUserID = i.ManageUserID,
                });
            });
            this.Delete(list);
        }
        #endregion

        #region IWebDepartmentsRepository 成员

        public IQueryable<WebManageUser_WebManageRoles> GetModel()
        {
            return GetEntities<WebManageUser_WebManageRoles>();
        }

        public WebManageUser_WebManageRoles Find(params object[] valueKeys)
        {
            return GetEntity<WebManageUser_WebManageRoles>(valueKeys);
        }

        #endregion
    }
}
